package apigateway.controller;

import apigateway.service.UserService;
import apigateway.serviceRegister.Anwser;
import apigateway.serviceRegister.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by 小泽玛丽罗 on 2016/9/29.
 */
@RestController
public class IndexController {
    private Logger logger= LoggerFactory.getLogger(IndexController.class);
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(){

        return "index";
    }

    @RequestMapping(value = "/getAll",method = RequestMethod.GET)
    public Anwser getAll(@RequestParam(value="uuid",required = false
            ,defaultValue = "null") String uuid){
        try {
            List<User> users=userService.getAll();
            Anwser<User> anwser=new Anwser();
            anwser.getAnwsers().addAll(users);
            anwser.setRowCount(users.size());
            System.out.println(uuid);
            return anwser;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("get users error",e);
            return null;
        }
    }
}
